package main

import (
	"fmt"
	"unicode"
)

func passwordComplexityScore(password string) int {
	// Check length
	if len(password) < 8 {
		return 2
	}

	var uppercase, lowercase, digit, specialChar bool
	for _, char := range password {
		switch {
		case unicode.IsUpper(char):
			uppercase = true
		case unicode.IsLower(char):
			lowercase = true
		case unicode.IsDigit(char):
			digit = true
		case unicode.IsPunct(char) || unicode.IsSymbol(char):
			specialChar = true
		}
	}

	for i := 0; i < len(password)-2; i++ {
		substr := password[i : i+3]
		if countSubstring(password, substr) > 1 {
			return 2
		}
	}

	score := 2
	if uppercase {
		score++
	}
	if lowercase {
		score++
	}
	if digit {
		score++
	}
	if specialChar {
		score++
	}

	return score
}

func countSubstring(str, substr string) int {
	count := 0
	for i := 0; i+len(substr) <= len(str); i++ {
		if str[i:i+len(substr)] == substr {
			count++
		}
	}
	return count
}

func main() {
	// Get password from user input
	var password string
	fmt.Print("Enter your password: \n")
	fmt.Scanln(&password)

	// Get password complexity score
	score := passwordComplexityScore(password)

	// Print the password complexity score
	fmt.Printf("Password Complexity Score: %d\n", score)
}
